package com.bdsoft.actions.menuManage.Controller;

import com.bdsoft.actions.AcUrls;
import com.bdsoft.actions.menuManage.DTO.MenuDTO;
import com.bdsoft.actions.menuManage.Service.MenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(AcUrls.menuManage.menuManageUrl)
@Tag(name = "菜单相关接口")
public class MenuController {
    @Autowired
    MenuService menuService;

    @Operation(summary = "获得菜单分页列表")
    @PostMapping(AcUrls.menuManage.getMenuList)
    public ResponseEntity getMenuList() {

        return ResponseEntity.ok(
                menuService.getMenuList());
    }
    @Operation(summary = "查询菜单左侧列表")
    @PostMapping(AcUrls.menuManage.getMenuListLeft)
    public ResponseEntity getMenuListLeft() {

        return ResponseEntity.ok(
                menuService.getMenuListLeft());
    }
    @Operation(summary = "给角色分配菜单")
    @PostMapping(AcUrls.menuManage.allocateMenu)

    public Map<String,Object> allocateMenu(@RequestParam String roleId, String menuIds
    )
    {
        return menuService.allocateMenu(roleId,menuIds);
    }
    @Operation(summary = "通过菜单id查询角色")
    @PostMapping(AcUrls.menuManage.findRoleByMenu)

    public Map<String, Object> findRoleByMenu(@RequestParam String menuId
    )
    {
        return menuService.findRoleByMenu(menuId);
    }
    @Operation(summary = "给菜单分配角色")
    @PostMapping(AcUrls.menuManage.allocateMenuByMenu)

    public Map<String,Object> allocateMenuByMenu(@RequestParam String menuId, String roleIds
    )
    {
        return menuService.allocateMenuByMenu(menuId,roleIds);
    }

    @Operation(summary = "新增菜单")
    @PostMapping(AcUrls.menuManage.addMenu)
    public ResponseEntity addMenu(@RequestBody MenuDTO menuDTO) {
        return ResponseEntity.ok(menuService.addMenu(menuDTO));
    }

    @Operation(summary = "修改菜单")
    @PostMapping(AcUrls.menuManage.updateMenu)
    public ResponseEntity updateMenu(@RequestBody MenuDTO menuDTO) {
        return ResponseEntity.ok(menuService.updateMenu(menuDTO));
    }

    @Operation(summary = "删除菜单")
    @PostMapping(AcUrls.menuManage.deleteMenu)
    public ResponseEntity deleteMenu(@RequestParam String menuId) {
        return ResponseEntity.ok(menuService.deleteMenu(menuId));
    }

    @Operation(summary = "根据ID获取菜单")
    @GetMapping(AcUrls.menuManage.getMenuById)
    public Map<String,Object> getMenuById(@RequestParam String menuId) {
        return menuService.getMenuById(menuId);
    }
} 